package cn.xiaomubiao.oschine.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xiaomubiao.oschine.R;
import cn.xiaomubiao.oschine.base.BaseRecyclerViewAdapter;
import cn.xiaomubiao.oschine.bean.Event;
import cn.xiaomubiao.oschine.util.UIUtils;

import static cn.xiaomubiao.oschine.util.UIUtils.getContext;

/**
 * Created by King Su on 2017/4/2.
 */

public class EventAdapter extends BaseRecyclerViewAdapter {
    List datas;

    public EventAdapter(List list) {
        datas = list;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(getContext()).inflate(R.layout.view_event_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(itemView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        Event event = (Event) datas.get(position);
        ViewHolder viewHolder = (ViewHolder) holder;
        Glide.with(getContext()).load(event.getCover()).override(UIUtils.dip2Px(50),UIUtils.dip2Px(80)).error(R.drawable.widget_dface).into(viewHolder.mIvEventa);
        viewHolder.mTvEventaAddress.setText(event.getSpot());
        viewHolder.mTvEventaData.setText(event.getStartTime());
        viewHolder.mTvEventaTitle.setText(event.getTitle());
        super.onBindViewHolder(holder, position);
    }

    @Override
    public int getItemCount() {
        return datas != null ? datas.size() : 0;
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_eventa)
        ImageView mIvEventa;
        @BindView(R.id.tv_eventa_title)
        TextView mTvEventaTitle;
        @BindView(R.id.tv_eventa_data)
        TextView mTvEventaData;
        @BindView(R.id.tv_eventa_address)
        TextView mTvEventaAddress;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
